package cn.itcast.zt;

import cn.itcast.zt.api.IUserApi;
import cn.itcast.zt.interfaces.ProxyCreator;
import cn.itcast.zt.proxys.JDKProxyCreator;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class SpringbootWebfluxClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootWebfluxClientApplication.class, args);
    }

    /**
     * 创建JDK代理
     * @return
     */
    @Bean
    ProxyCreator jdkProxyCreator(){
        return new JDKProxyCreator() ;
    }

    @Bean
    public FactoryBean<IUserApi> userApi(ProxyCreator proxyCreator){
        return new FactoryBean<IUserApi>() {
            /**
             * 返回代理对象
             * @return
             * @throws Exception
             */
            @Override
            public IUserApi getObject() throws Exception {
                return (IUserApi) proxyCreator.createProxy(this.getObjectType());
            }

            @Override
            public Class<?> getObjectType() {
                return IUserApi.class;
            }
        } ;
    }
}
